package com.igs.muziapp.utils;
import android.util.Log;

public class PlatformUtils {
	// ---------------------------------------------------
	// JNI
	static {
		System.loadLibrary("PlatformUtils-jni");
	}

	public native String stringFromJNI();

	// public native void ReceiveResponse();
	// public native void Post(Object obj);
	private native void Post(String ip, String cmd, String data, int type, int timeout, String callback);

	private native void Get(String ip, String cmd, String data, int type, int timeout, String callback, String control);

	// ---------------------------------------------------
	// Singleton
	private static final PlatformUtils instance = new PlatformUtils();

	private PlatformUtils() {
	}

	public static PlatformUtils getInstance() {
		return instance;
	}

	// ---------------------------------------------------
	// CallBack
	private static HttpOnRequestListener listener;
	private void onHttpRequestCompleted(String jsonData) {
		Log.d("PlatformUtils", "jsonData:" + jsonData);
		if (this.listener != null) {
			this.listener.RequestCompleted(jsonData);
		}
	}
	// ---------------------------------------------------
	public void Post(String ip, String cmd, String data, int type, int timeout, HttpOnRequestListener listener) {
		this.listener = listener;
		Post(ip, cmd, data, type, timeout, "onHttpRequestCompleted");
	}

	public void Get(String ip, String cmd, String data, int type, int timeout, HttpOnRequestListener listener, String control) {
		this.listener = listener;
		Get(ip, cmd, data, type, timeout, "onHttpRequestCompleted", control);
	}

}
